/*
 Stepper Motor Control - one revolution
 This program drives a unipolar or bipolar stepper motor.
 The motor is attached to digital pins 8 - 11 of the Arduino.
 The motor should revolve one revolution in one direction, then
 one revolution in the other direction.
 Created 11 Mar. 2007
 Modified 30 Nov. 2009
 by Tom Igoe
 */
#include <Stepper.h>
#include <Servo.h>

const int stepsPerRevolution = 20;  // change this to fit the number of steps per revolution
// for your motor
Servo myservo; // create servo object to control a servo

// initialize the stepper library on pins 8 through 11:

#define CLK 10
#define CW 9
#define EN 8

void setup() {
  // set the speed at 60 rpm:
  pinMode(CLK,OUTPUT);
  pinMode(CW,OUTPUT);
  pinMode(EN,OUTPUT);  
  // initialize the serial port:
  Serial.begin(115200);
  digitalWrite(EN,LOW);
  myservo.attach(12); // attaches the servo on pin 9 to the servo object
}

void loop() {
     char data[20] = {0};
     digitalWrite(EN,LOW);

  // step one revolution  in one direction:
     if(Serial.available()){ //if number of bytes (characters) available for reading from { 
        Serial.readBytes(data,20);
        Serial.print("I received:"); //print I received
        Serial.write(data); //send what you read
        String strInt = data;    // string to hold input
        int ints = strInt.toInt();
        Serial.print(ints); //print I received
        myservo.write(ints); // sets the servo position according to the scaled value
        for(int cnt = 0;cnt < ints;cnt++){
          delay(100);          
          digitalWrite(EN,LOW);
          delay(100);
          digitalWrite(EN,HIGH);

        }
        ints = 0;
     }
}
